package main

import (
	"context"
	"fmt"
	"net"
	"project1/day05/pb"

	"google.golang.org/grpc"
)

// 定义类
type Children struct {
	pb.UnimplementedSayNameServer // 添加这一行
}

func (this *Children) mustEmbedUnimplementedSayNameServer() {
	//TODO implement me
	panic("implement me")
}

// 按接口绑定类方法
func (this *Children) SayHello(ctx context.Context, t *pb.Teacher) (*pb.Teacher, error) {
	t.Name += " is Sleeping"
	return t, nil
}
func main() {
	//1.创建一个grpcd对象
	grpcServer := grpc.NewServer()
	//2.注册服务
	pb.RegisterSayNameServer(grpcServer, new(Children))
	//3.设置监听，指定IP port
	listenser, err := net.Listen("tcp", "127.0.0.1:8800")
	if err != nil {
		fmt.Println("listen err:", err)
		return
	}
	defer listenser.Close()
	//4.启动服务
	grpcServer.Serve(listenser)
}
